package com.huawei.gamebox.service.welfare.campaign.node;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.gamebox.service.common.cardkit.bean.BaseGsCardBean;
import com.huawei.gamebox.service.common.cardkit.card.BaseGsCard;
import com.huawei.gamebox.service.common.cardkit.node.BaseGsNode;
import com.huawei.gamebox.service.welfare.campaign.card.BaseCampaignCard;
import com.huawei.gamebox.service.welfare.campaign.card.CampaignWithTitleCard;
import com.huawei.gamebox.service.welfare.common.bean.AbsWithTitleCardBean;
import com.huawei.gamebox.service.welfare.common.card.AbsWithTitleCard;
import com.huawei.gamebox.service.welfare.common.card.GsTitleCard;
import java.util.List;
import o.azb;
import o.cgz;
import o.chy;
import o.chz;
import o.cih;
import o.epv;
import o.CollectCheck;
import o.exp$a;
import o.exp$c;
import o.exp$e;
import o.exp$f;
import o.exp.d;
import o.exp.j;
import o.eys;
import o.fcs;

public abstract class BaseCampaignWithTitleNode extends BaseGsNode {
    protected chy ˊ;
    private int ᐝ = 1;

    static class c extends fcs {
        private final cgz ˊ;

        c(chy o_chy, cgz o_cgz, int i) {
            super(o_chy, o_cgz, i);
            this.ˊ = o_cgz;
        }

        public void onClick(View view) {
            super.onClick(view);
            if (this.ˊ != null) {
                CardBean ˌ = this.ˊ.ˌ();
                if (ˌ instanceof BaseGsCardBean) {
                    BaseGsCardBean baseGsCardBean = (BaseGsCardBean) ˌ;
                    eys.ˏ(baseGsCardBean.ͺˏ(), "ACTIVITIES", baseGsCardBean.ॱॱ());
                }
            }
        }
    }

    protected abstract String ʻ();

    protected abstract int ʼ();

    protected abstract BaseCampaignCard ˏ(boolean z);

    public BaseCampaignWithTitleNode(Context context) {
        super(context);
    }

    public int ˏ() {
        return 1;
    }

    void ॱ(int i) {
        this.ᐝ = i;
    }

    public boolean ॱ() {
        return true;
    }

    protected int ॱॱ() {
        return j.ʻॱ;
    }

    protected View ˎ() {
        LayoutInflater from = LayoutInflater.from(this.ॱ);
        int i = j.ॱͺ;
        if (ˋ()) {
            i = j.ᐝॱ;
        }
        LinearLayout linearLayout = (LinearLayout) from.inflate(i, null);
        if (!ˋ()) {
            azb.ˏ(linearLayout);
        }
        TextView textView = (TextView) linearLayout.findViewById(d.ᶥ);
        textView.setText(this.ॱ.getText(exp$f.ᐝॱ));
        if (ˋ()) {
            ((TextView) linearLayout.findViewById(d.ꜞ)).setTextColor(this.ॱ.getResources().getColor(exp$c.ʽ));
            textView.setTextColor(this.ॱ.getResources().getColor(exp$c.ˋ));
            ((ImageView) linearLayout.findViewById(d.ㆍ)).setImageResource(exp$e.ॱˊ);
        }
        ॱ(linearLayout);
        return linearLayout;
    }

    protected void ॱ(LinearLayout linearLayout) {
    }

    public boolean ˊ(ViewGroup viewGroup, ViewGroup viewGroup2) {
        LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
        layoutParams.weight = 1.0f;
        int ˏ = ˏ();
        LayoutInflater from = LayoutInflater.from(this.ॱ);
        for (int i = 0; i < ˏ; i++) {
            cih campaignWithTitleCard = new CampaignWithTitleCard(this.ॱ);
            LinearLayout linearLayout = (LinearLayout) from.inflate(ॱॱ(), null);
            LinearLayout linearLayout2 = (LinearLayout) linearLayout.findViewById(d.ՙ);
            LinearLayout linearLayout3 = (LinearLayout) linearLayout.findViewById(d.ˉ);
            GsTitleCard gsTitleCard = new GsTitleCard(this.ॱ);
            View ˎ = ˎ();
            gsTitleCard.ˏ(ˎ);
            linearLayout2.addView(ˎ);
            campaignWithTitleCard.ˊ(gsTitleCard);
            View linearLayout4 = new LinearLayout(this.ॱ);
            LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-1, -2);
            linearLayout4.setOrientation(1);
            linearLayout4.setLayoutParams(layoutParams2);
            campaignWithTitleCard.ˊ(linearLayout4);
            linearLayout3.addView(linearLayout4);
            ˊ(campaignWithTitleCard);
            viewGroup.addView(linearLayout, layoutParams);
        }
        return true;
    }

    public boolean ॱ(chz o_chz, ViewGroup viewGroup) {
        int i;
        int ˏ = ˏ();
        this.ˏ = o_chz.ˏ;
        if (epv.ˏॱ(this.ॱ)) {
            i = this.ᐝ;
        } else {
            i = 1;
        }
        for (int i2 = 0; i2 < ˏ; i2++) {
            cih ˎ = ˎ(i2);
            if (ˎ instanceof AbsWithTitleCard) {
                AbsWithTitleCard absWithTitleCard = (AbsWithTitleCard) ˎ;
                CardBean ˋ = o_chz.ˋ(i2);
                if (ˋ instanceof AbsWithTitleCardBean) {
                    ˋ.ˋˋ(String.valueOf(this.ˏ));
                    List ˊ = ((AbsWithTitleCardBean) ˋ).ˊ();
                    if (CollectCheck.isEmpty(ˊ)) {
                        ˎ.ˉ().setVisibility(8);
                    } else {
                        ˏ(absWithTitleCard, ˊ.size(), i);
                        absWithTitleCard.ॱ(ʻ());
                        absWithTitleCard.ˏ(ˋ);
                        ˎ.ˉ().setVisibility(0);
                    }
                } else {
                    ˎ.ˉ().setVisibility(8);
                }
            }
        }
        return true;
    }

    int ᐝ() {
        if (ˋ()) {
            return this.ॱ.getResources().getDimensionPixelSize(exp$a.ᐝ);
        }
        return azb.ˊ(this.ॱ);
    }

    protected void ˏ(AbsWithTitleCard absWithTitleCard, int i, int i2) {
        absWithTitleCard.ˋ();
        View ˉ = absWithTitleCard.ˉ();
        if (ˉ instanceof ViewGroup) {
            ((ViewGroup) ˉ).removeAllViews();
        }
        LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
        layoutParams.weight = 1.0f;
        LinearLayout linearLayout = null;
        LayoutInflater from = LayoutInflater.from(this.ॱ);
        int i3 = 0;
        boolean z = false;
        while (i3 < i) {
            boolean z2;
            LinearLayout linearLayout2;
            if (i2 <= 1) {
                z2 = i3 == i + -1;
                linearLayout2 = linearLayout;
            } else if (linearLayout == null || i3 % i2 == 0) {
                View linearLayout3 = new LinearLayout(this.ॱ);
                linearLayout3.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
                linearLayout3.setOrientation(0);
                if (ˉ instanceof ViewGroup) {
                    ((ViewGroup) ˉ).addView(linearLayout3, layoutParams);
                }
                z2 = i - (i3 + 1) < i2;
                linearLayout2 = linearLayout3;
            } else {
                z2 = z;
                linearLayout2 = linearLayout;
            }
            ViewGroup viewGroup = (ViewGroup) from.inflate(ʼ(), null);
            if (viewGroup != null) {
                int ᐝ = ᐝ();
                viewGroup.setPadding(ᐝ, 0, ᐝ, 0);
                BaseGsCard ˏ = ˏ(z2);
                ˏ.ˏ = true;
                ˏ.ˊ = i3 < i2;
                ˏ.ˏ(viewGroup);
                absWithTitleCard.ॱ(ˏ);
                LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-1, -1);
                layoutParams2.weight = 1.0f;
                if (i2 > 1 && linearLayout2 != null) {
                    linearLayout2.addView(viewGroup, layoutParams2);
                    if (i3 == i - 1 && i3 % i2 == 0) {
                        linearLayout2.addView(new View(this.ॱ), layoutParams2);
                    }
                } else if (ˉ instanceof ViewGroup) {
                    ((ViewGroup) ˉ).addView(viewGroup, layoutParams);
                }
                ˊ(z2, viewGroup);
            }
            i3++;
            linearLayout = linearLayout2;
            z = z2;
        }
        ˋ(this.ˊ);
    }

    private void ˊ(boolean z, ViewGroup viewGroup) {
        if (z && viewGroup.findViewById(d.ʽॱ) != null) {
            viewGroup.findViewById(d.ʽॱ).setVisibility(8);
        }
    }

    public void ˋ(chy o_chy) {
        this.ˊ = o_chy;
        int ˊॱ = ˊॱ();
        for (int i = 0; i < ˊॱ; i++) {
            AbsWithTitleCard absWithTitleCard = (AbsWithTitleCard) ˊ(i);
            if (absWithTitleCard != null) {
                absWithTitleCard.ˊ().ॱ(o_chy);
                int ˎ = absWithTitleCard.ˎ();
                int i2 = 0;
                while (i2 < ˎ) {
                    cgz ˋ = absWithTitleCard.ˋ(i2);
                    if (ˋ != null) {
                        View ˉ = ˋ.ˉ();
                        if (ˉ != null) {
                            ˉ.setOnClickListener(new c(o_chy, ˋ, 0));
                            ˉ.setClickable(true);
                        }
                        i2++;
                    } else {
                        return;
                    }
                }
                continue;
            }
        }
    }
}
